/**
* @Title: ConfigurationFactory.java
* @Package com.yly.module.system.staticpage
* @Description: TODO
* @author zz
* @date 2013-12-20 下午2:54:27
* @version V1.0
*/
package com.yly.utils.staticpage;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import com.yly.constant.Constant;
import com.yly.utils.StrUtil;

import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;

/**
 * @ClassName: ConfigurationFactory
 * @Description: TODO
 * @author zz
 * @date 2013-12-20 下午2:54:27
 */
public class ConfigurationFactory {

	private static final Configuration CFG = new Configuration();
	
	private ConfigurationFactory(){}
	
	public static Configuration getConfiguration(){
		
		return CFG;
	}
	
	static {
		
		try {
			
			CFG.setDirectoryForTemplateLoading(new File(Constant.SP_DIRECTORY_TEMPLATE));
			
			CFG.setEncoding(Locale.CHINA, Constant.SP_ENCODING);
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		/*List<TemplateLoader> loaderList = new ArrayList<TemplateLoader>();
		
		loaderList.addAll(getTemplateLoaders(Constant.DIRECTORY_TEMPLATE));

		loaderList.addAll(getTemplateLoaders(Constant.CLASS_TEMPLATE));

		loaderList.addAll(getTemplateLoaders(Constant.SERVLETCONTEXT_TEMPLATE));
		
		if(!loaderList.isEmpty()){
		
			@SuppressWarnings("unused")
			Object[] list = loaderList.toArray();
			
			MultiTemplateLoader mtl = new MultiTemplateLoader((TemplateLoader[])loaderList.toArray());
			
			CFG.setTemplateLoader(mtl);
		
		}*/

	}
	
	
	public static void reloadTtemplate(String templatePath) throws IOException{
		CFG.removeTemplateFromCache(templatePath);
	}
	
	/*private static List<TemplateLoader> getTemplateLoaders(String templateStr){
		List<TemplateLoader> tmpList = new ArrayList<TemplateLoader>();
		if(!StrUtil.nil(templateStr)){
			String[] tmpArr = templateStr.split(",");
			for(String tmpStr : tmpArr){
				try {
					TemplateLoader ftl = new FileTemplateLoader(new File(tmpStr));
					tmpList.add(ftl);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return tmpList;
	}*/
	
	
	
	
}
